package cn.wzut.edut.controller;

import cn.wzut.edut.pojo.JsonResult;
import cn.wzut.edut.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Validated
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    /**
     * 添加菜单赋予的角色请求
     * @param menuId
     * @param roleIds
     * @return
     */
    @PostMapping("/add/role")
    public JsonResult addMenuRole(@RequestParam(value = "menuid") @NotNull String menuId,
                                  @RequestParam(value = "role_id") @NotNull String[] roleIds){
        return new JsonResult(menuService.addMenuRole(menuId, roleIds));
    }

    /**
     * 移除菜单赋予的角色请求
     * @param menuId
     * @param roleIds
     * @return
     */
    @PostMapping("/del/role")
    public JsonResult delMenuRole(@RequestParam(value = "menu_id") @NotNull String menuId,
                                  @RequestParam(value = "role_id") @NotNull String[] roleIds){
        return new JsonResult(menuService.delMenuRole(menuId, roleIds));
    }

    /**
     * 获取菜单列表请求
     * @return
     */
    @GetMapping("/get/list")
    public JsonResult getMenuList(){
        return new JsonResult(menuService.getMenuList());
    }





//    /**
//     * 查询菜单请求
//     * @param request 请求头参数
//     * @return
//     */
//    @GetMapping("/query")
//    public JsonResult getMenuByName(HttpServletRequest request, long pagenum, long pagesize, String menuname){
//        String token = request.getHeader("token"); // 获取请求头中的token
//        return new JsonResult(menuService.queryMenu(token, pagenum, pagesize, menuname));
//    }
//
//
//
//    /**
//     * 更改菜单赋予角色请求
//     * @param request 请求头参数
//     * @return
//     */
//    @PostMapping("/update")
//    public JsonResult updateMenuByRole(HttpServletRequest request, MenuRoleRelModInfo menuRoleRelModInfo){
//        String token = request.getHeader("token"); // 获取请求头中的token
//        return new JsonResult(menuService.modMenuByRole(token, menuRoleRelModInfo));
//    }

}
